package com.zerocarbon.declaration.server.config;

import com.zerocarbon.framework.db.config.DefaultMybatisPlusConfig;
import com.zerocarbon.framework.db.mybatis.auth.DataScopeInterceptor;
import com.zerocarbon.framework.db.properties.DatabaseProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

import java.util.Map;
import java.util.function.Function;

/**
 * 配置一些 Mybatis 常用重用拦截器
 */
@Slf4j
@Configuration
public class MybatisConfiguration extends DefaultMybatisPlusConfig {

    /**
     * 数据权限插件
     *
     * @return DataScopeInterceptor
     */
    @Order(10)
    @Bean
    @ConditionalOnProperty(prefix = DatabaseProperties.PREFIX, name = "isDataScope", havingValue = "true", matchIfMissing = true)
    public DataScopeInterceptor dataScopeInterceptor() {
        //return new DataScopeInterceptor((userId) -> SpringContextUtil.getBean(UserApi.class).getDataScopeById(userId));
    	return new DataScopeInterceptor(new Function<Long, Map<String,Object>>() {
			
			@Override
			public Map<String, Object> apply(Long t) {
				
				return null;
			}
		});
    }

}
